package common

import (
	"encoding/json"
	"io/ioutil"
	"path"
)

var Conf Config

type Config struct {
	LogSavePath    string    `json:"logSavePath"`
	LogFileName    string    `json:"logFileName"`
	HttpListener   int       `json:"httpListener"`
	LogCount       int       `json:"logCount"`
	MonitorCycle   int       `json:"monitorCycle"`
	MonitorService string    `json:"monitorService"`
	AppInfos       []AppInfo `json:"app_infos"`
}

type AppInfo struct {
	Name          string `json:"name"`
	ProcessScript string `json:"process_script"`
	StartScript   string `json:"start_script"`
}

func InitConfig(dir string) (err error) {
	js, err := ioutil.ReadFile(path.Join(dir, "config.json"))
	if err != nil {
		return
	}
	err = json.Unmarshal(js, &Conf)
	return
}
